from enum import Enum
from typing import List, Optional


class UserRoleEnum(Enum):
    USER = ("用户", "user")
    ADMIN = ("管理员", "admin")
    BAN = ("被封号", "ban")

    def __init__(self, text: str, value: str):
        self._text = text
        self._value = value

    @classmethod
    def get_values(cls) -> List[str]:
        return [item._value for item in cls]

    @classmethod
    def get_enum_by_value(cls, value: str) -> Optional['UserRoleEnum']:
        for item in cls:
            if item._value == value:
                return item
        return None

    def get_value(self) -> str:
        return self._value

    def get_text(self) -> str:
        return self._text


# 示例用法
if __name__ == "__main__":
    # # 获取所有值列表
    # print(UserRoleEnum.get_values())  # 输出: ['user', 'admin', 'ban']
    #
    # # 根据值获取枚举
    # print(UserRoleEnum.get_enum_by_value("admin"))  # 输出: UserRoleEnum.ADMIN
    # print(UserRoleEnum.get_enum_by_value("admin").get_value())
    # print(UserRoleEnum.get_enum_by_value("admin").get_text())
    #
    # # 获取枚举的值和文本
    # print(UserRoleEnum.USER.get_value())  # 输出: user
    # print(UserRoleEnum.USER.get_text())  # 输出: 用户

    print(UserRoleEnum.ADMIN.value[1])
    print(UserRoleEnum.USER)  # 输出: UserRoleEnum.USER
    print(UserRoleEnum(("被封号", "ban")).name)  # 输出: BAN
    print(UserRoleEnum(("被封号", "ban")).value[0])  # 输出: 被封号
    print(UserRoleEnum["BAN"].get_value())  # 输出: ban
    print(UserRoleEnum["BAN"].get_text())  # 输出: 被封号
